#include<p18f4520.h>
#include"config.h"
#pragma config OSC=HS, FCMEN=OFF, IESO=OFF, WDT=OFF, LVP=OFF 


union{
unsigned char status;
struct{
unsigned volt_status:1;			//0 for normal voltage 1 for high voltage
unsigned motor_status:1;		//0 for device is off  1 for device is on
unsigned sensor_up:2;			//0 for low water 2 for full water
unsigned sensor_bot:2;			//0 for low water 2 for full water
unsigned mode_0:1 ; 			//0 for auto/ 1 for manual
unsigned mode_1:1; 				//on/off switch
 };
}statusbits;


unsigned int adc_value[3]={0,0,0};		//assumed array 0 holds voltage


void high_isr(void);
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}
#pragma code 

#pragma code low_vector=0x18
void interrupt_at_low_vector(void)
{

}
#pragma code


#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.ADIF)
{
ADC_scan();
PIR1bits.ADIF=0;
}
else		//INT0 for  auto/manual, INT1 for on/0ff
{
mode_control();
INTCON3bits.INT1IF=INTCONbits.INT0IF=0;
}}




void main(void)
{
TRISEbits.TRISE0=0;		//configure the port connected to relay to o/p
statusbits.status=0;		//set device to default mode
init_ADC();
//display "INITIALISING" till it does the conversion of all three adc channels


while(1)
{
v_over(adc_value[0]);
display_voltage(adc_value[0]);
uptank(adc_value[1]);
sump(adc_value[2]);
device_control();
}}


